package msg.visitors;

import msg.EventMessage;
import msg.Message;

import org.json.JSONObject;

import common.interfaces.IMessageVisitor;

/**
 * Constructs a {@link JSONObject} of the message
 * 
 * @author Gal Lalouche
 */
public class MessageToJson implements IMessageVisitor<JSONObject> {
	@Override
	public JSONObject visit(Message message) {
		JSONObject result = new JSONObject();
		result.put("id", message.getId());
		result.put("content", message.getContent());
		JSONObject location = new JSONObject();
		location.put("lat", message.getLocation().getLatitude());
		location.put("long", message.getLocation().getLongitude());
		location.put("address", message.getLocation().getAddress());
		result.put("location", location);
		result.put("poster", message.getPoster().getId());
		result.put("time", message.getTime());
		result.put("name", message.getPoster().getName());
		return result;
	}

	@Override
	public JSONObject visit(EventMessage event) {
		JSONObject result = visit((Message)event);
		result.put("capacity", event.getCapacity());
		return result;
	}
}
